//
//  TextInputView.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/10/8.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class TextInputView: UIView {
    var takeBackKeyboardIcon:UIButton!
    var scrollView:UIScrollView!
    var itemText = ["文字","插入","代码","引用","排列"]
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        takeBackKeyboardIcon = UIButton()
        scrollView = UIScrollView()
        self.backgroundColor = Theme.BGColor
        self.addLineView()
        self.addTakeBackKeyboardIcon()
        self.addLineForIconAndScrollView()
        self.addScrollView()
        self.addallEditItemButton()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加一条最上面的线
    func addLineView(){
        let line = UIView(frame: CGRectMake(0,0,WidthAPP,0.5))
        line.backgroundColor = BaseFunc.createCustomColor(199, b: 199, g: 199, a: 1)
        self.addSubview(line)
    }
    
    //收回键盘的按钮
    func addTakeBackKeyboardIcon(){
        takeBackKeyboardIcon.frame = CGRectMake(15*SCALEW, 11*SCALEH, 27*SCALEW, 23.5*SCALEH)
        takeBackKeyboardIcon.setImage(UIImage(named: "keyBoIcon"), forState: .Normal)
        self.addSubview(takeBackKeyboardIcon)
    }
    
    //添加分割线
    func addLineForIconAndScrollView(){
        let line = UIView(frame: CGRectMake(56*SCALEW,9*SCALEH,0.5,26*SCALEH))
        line.backgroundColor = BaseFunc.createCustomColor(199, b: 199, g: 199, a: 1)
        self.addSubview(line)
    }
    
    //添加底册scrollView
    func addScrollView(){
        scrollView.frame = CGRectMake(57*SCALEW, 0, WidthAPP-57*SCALEW, 45*SCALEH)
        scrollView.contentSize = CGSizeMake(360*SCALEW, 45*SCALEH)
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.showsVerticalScrollIndicator = false
        self.addSubview(scrollView)
    }
    
    //添加所有的编辑选项
    func addallEditItemButton(){
        for i in 0..<5{
            let button = UIButton(frame: CGRectMake(10*SCALEW+CGFloat(i)*70*SCALEW,8*SCALEH,60*SCALEW,30*SCALEH))
            button.titleLabel?.font = BaseFunc.getLightFont(16)
            button.setTitle("\(self.itemText[i])", forState: .Normal)
            button.setTitleColor(Theme.editBlue, forState: .Normal)
            button.setBackgroundImage(UIImage(named: "selecteB"), forState: .Normal)
            button.setBackgroundImage(UIImage(named: "noSelecteB"), forState: .Selected)
            button.tag = 1660+i
            scrollView.addSubview(button)
            if i == 0{
                button.selected = true
            }else{
                button.selected = false
            }
        }
    }
}








